package cn.luna.datasource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.TransactionDefinition;
public class ManagedJpaTransactionManager extends JpaTransactionManager {
	private static final long serialVersionUID = 1L;
	@Override
	protected void doBegin(Object transaction, TransactionDefinition definition) {
		System.out.println("definition.isReadOnly() is "+definition.isReadOnly());
		if(!definition.isReadOnly()){
			OperationHolder.setDataSourceType(DataSourceType.WRITE);
		}
		super.doBegin(transaction, definition);
	}
	@Override
	protected void doCleanupAfterCompletion(Object transaction) {
		super.doCleanupAfterCompletion(transaction);
		OperationHolder.clearDataSourceType();
	}
}
